package com.ruoyi.business.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.CustomerAddress;
import com.ruoyi.business.service.ICustomerAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.Arrays;
import java.util.List;

/**
 * customer_addressController
 *
 * @author liutietou
 * @since 1.0 2025-07-19
 */
@RestController
@RequestMapping("/business/address")
public class CustomerAddressController extends BaseController {
    @Autowired
    private ICustomerAddressService customerAddressService;

    /**
     * 查询customer_address列表
     */
    @PreAuthorize("@ss.hasPermi('business:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustomerAddress customerAddress) {
        Page<CustomerAddress> page = customerAddressService.findCustomerAddressPage(customerAddress);
        return getDataTable(page);
    }

    /**
     * 导出customer_address列表
     */
    @PreAuthorize("@ss.hasPermi('business:address:export')")
    @Log(title = "customer_address", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerAddress customerAddress) {
        List<CustomerAddress> list = customerAddressService.findCustomerAddressList(customerAddress);
        ExcelUtil<CustomerAddress> util = new ExcelUtil<>(CustomerAddress.class);
        return util.exportExcel(list, "address");
    }

    /**
     * 获取customer_address详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(customerAddressService.findById(id));
    }

    /**
     * 新增customer_address
     */
    @PreAuthorize("@ss.hasPermi('business:address:add')")
    @Log(title = "customer_address", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerAddress customerAddress) {
        customerAddressService.save(customerAddress);
        return AjaxResult.success();
    }

    /**
     * 修改customer_address
     */
    @PreAuthorize("@ss.hasPermi('business:address:edit')")
    @Log(title = "customer_address", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerAddress customerAddress) {
        customerAddressService.save(customerAddress);
        return AjaxResult.success();
    }

    /**
     * 删除customer_address
     */
    @PreAuthorize("@ss.hasPermi('business:address:remove')")
    @Log(title = "customer_address", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        customerAddressService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
}
